package com.lglbc.factory.simple;

import com.lglbc.factory.entity.BlackCar;
import com.lglbc.factory.entity.Car;
import com.lglbc.factory.entity.YellowCar;

import java.util.HashMap;
import java.util.Map;
/**
 * @author： 乐哥聊编程(全平台同号)
 */
public class SimpleFactory {
    private Map<String, Car> mapCar = new HashMap<>();
    public SimpleFactory(){
        mapCar.put("yellow",new YellowCar());
        mapCar.put("black",new BlackCar());
    }
    public Car createCar(String color){
        System.out.println(String.format("简单工厂正在生产%s汽车", color));
        Car car = mapCar.get(color);
        if (null == car) {
            System.out.println("对不起，没有这种颜色的汽车");
        }
        return car;
    }
}